// 存放用户收货地址address 和用户token
export default {
	// 开启命名空间
	namespaced:true,
	
	// 数据
	state:()=>({
		address:JSON.parse(uni.getStorageSync('address') || '{}'),
		token:uni.getStorageSync('token') || '',
		userInfo:JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		redirectInfo:null//重定向的Object对象 {openType,from}
	}),
	mutations:{
		// 更新redirectInfo
		updataRedirectInfo(state,redirectInfo){
			state.redirectInfo = redirectInfo;
		},
		
		// 更新token
		updataToken(state,token){
			state.token = token;
			this.commit('m_user/setTokenToStorage')
		},
		// 将token持久化保存到本地
		setTokenToStorage(state){
			uni.setStorageSync('token',state.token)
		},
		
		// 更新收货地址
		updateAddress(state,address){
			console.log('1',state.address)
			state.address = address;
			console.log('2',state.address)
			this.commit('m_user/setAddressToStorage')
		},
		// 将收货地址存到本地存储
		setAddressToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address));
		},
		
		// 更新用户信息
		updataUserInfo(state,userinfo){
			state.userInfo = userinfo;
			this.commit('m_user/setUserInfoToStroage')
		},
		// 将用户信息存到本地存储
		setUserInfoToStroage(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userInfo))
		}
	},
	getters:{
		addstr(state){
			if(state.address.provinceName !== ''){
				return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo 
			}
		}
	}
}